package pers.vic.test.json;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import lombok.Data;

public class FastJsonDisableCircularReferenceDetect {

    public static void main(String[] args) {
        TestJson test = new TestJson();

        String json = JSONObject.toJSONString(test, SerializerFeature.DisableCircularReferenceDetect);
        System.out.println(json);
    }
}

@Data
class TestJson {

    private int id;

    private String name;

    private TestJson parent = new TestJson();

    public String getFullName() {
        StringBuffer sb = new StringBuffer();
        TestJson parent = this.parent;
        if (parent != null) {
            sb.append(parent.getName());
            parent = parent.getParent();
        }
        return sb.toString();
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the parent
     */
    public TestJson getParent() {
        return parent;
    }

    /**
     * @param parent
     *            the parent to set
     */
    public void setParent(TestJson parent) {
        this.parent = parent;
    }

}
